﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Params_P18_9 {
    internal class Program {
        static void Main(string[] args) {
           int[] arry = new int[] { 1, 2, 3 };
           int sum = CalculateSum(arry);
            //如果 CalculateSum 方法没加 params 关键字则就只能像上面那样调用
            //但是只能是参数列表中的最有一个参数
            int paramSum = CalculateSum(1, 2, 3);
            Console.WriteLine(sum + "  ====  "+paramSum);
            Console.ReadLine();
        }

        static int CalculateSum(params int[] intArray) { 
            int sum = 0;
            for (int i = 0; i < intArray.Length; i++){
                sum += intArray[i];
            }
            return sum;
        }
    }
}
